<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8" %> 
<%@page import="org.ipo.mm.web.util.ConstantManager, java.util.List, org.ipo.mm.ejb.entities.Representative,java.util.Iterator,org.ipo.mm.ejb.entities.Institution" %>
<%@taglib prefix="h" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="l" uri="http://struts.apache.org/tags-logic" %>
<%@ taglib prefix="b" uri="http://struts.apache.org/tags-bean" %>


        <h1><b:message key="repr_create"/></h1>


<div id="reprForm">
<fieldset>
    <h:form styleClass="form"  styleId="addReprForm" action="/protected/representative?method=${param['method']}">
        <h:errors property="name" />
        <table border="0">

            <tr>
                <td><span class="important"><b:message key="repr_firstName"/></span></td>
                <td>
				<h:text property="firstName" styleId="repFirstName" styleClass="required" size="100" maxlength="512"/>
				<span class="error" ><h:errors property="firstName" /></span></td>
                <td>
                    <%
                                List<Representative> similars = (List<Representative>) request.getAttribute(ConstantManager.REQUEST_REPRESENTATIVES_SIMILARS);

                                if (similars != null) {

                    %>
                    <div style="border-style:solid; border-color:red;">
                        <b:message key="repr_similars_warning"/>
                        <l:iterate id="repr" name="REPRESENTATIVES_SIMILARS">
                            <br>
                            ${repr.firstName},${repr.lastName},${repr.institution.name}
                        </l:iterate>
                        <p>
                            <b:message key="gen_confirm_operation_question"/>
                        </p>

                        <br>
                        <h:submit property="operation" ><b:message key="gen_confirm_operation"/></h:submit>
                        <h:cancel><b:message key="gen_cancel"/></h:cancel>
                    </div>

                    <%}%>





                </td>
            </tr>
            <tr>
                <td><span class="important"><b:message key="repr_lastName"/></span></td>
                <td><h:text property="lastName" styleClass="required" styleId="repLastName" size="100" maxlength="512"/><span class="error" ><h:errors property="lastName" /></span></td>
            </tr>
            <tr>
                <td><span class="important"><b:message key="repr_inst" /></span></td>
                <td>
                    <h:select property="institution" styleId="SelInst4Rep" styleClass="required combo">
                        <h:option value="" ><b:message key="repr_inst_choose" /></h:option>

                        <l:iterate id="inst" name="dispatcher.showCreateReprForm.insts">
                            <h:option value="${inst.id}">
                                <b:write name="inst" property="name"/>
                            </h:option>
                        </l:iterate>
                    </h:select> 
                        <h:submit property="operation" styleClass="hideInDialog" onclick="$('#addReprForm').validate().cancelSubmit = true;"><b:message key="inst_create"/></h:submit>
                    <span class="error" ><h:errors property="institution" /></span>
                </td>
            </tr>
            <tr>
                <td><b:message key="repr_function" /></td>
                <td><h:text property="function" size="100" maxlength="512"/></td>
            </tr>
            <tr>
                <td><b:message key="gen_email" /></td>
                <td><h:text property="email" styleClass="email" styleId="repEmail" size="100" maxlength="512"/>
				<div id="sendEmail"></div>
				
</td>
            </tr>
            <tr>
                <td><b:message key="gen_telephone" /></td>
                <td><h:text property="telephone" size="100" maxlength="512"/></td>
            </tr>
            <tr>
                <td><b:message key="gen_fax" /></td>
                <td><h:text property="fax" size="100" maxlength="512"/></td>
            </tr>
            <tr>
                <td><b:message key="gen_note" /></td>
                <td><h:textarea property="note" cols="100" rows="10" /></td>
            </tr>
        </table>
        <c:if test="${param['method'] == 'showCreateReprForm'}">

            <c:choose>
                <c:when test="${not empty REPRESENTATIVES_SIMILARS}">
                    <h:submit property="operation"><b:message key="gen_confirm_operation"/></h:submit>
                </c:when>
                <c:otherwise>
                    <h:submit property="operation"><b:message key="gen_create"/></h:submit>
                </c:otherwise>
            </c:choose>




        </c:if>

        <c:if test="${param['method'] == 'showUpdateReprForm'}">
            <h:submit property="operation"><b:message key="gen_update"/></h:submit>
        </c:if>

        <!--<h:cancel onclick="$('#reprDialog').dialog('close');return false;"><b:message key="gen_cancel"/></h:cancel>-->
    	<input type="reset" value="<b:message key="gen_cancel"/>" onclick="cancelForm();"/>



    </h:form>
	
</fieldset>
</div>

<script type="text/javascript">
//alert($('#reprEmail').val());
</script>

<script type="text/javascript">
function cancelForm(){
		history.go(-1);
}
</script>